package com.zj.core.ui

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.view.Gravity
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.LinearLayout.HORIZONTAL
import android.widget.LinearLayout.VERTICAL
import android.widget.TextView
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.constraint.layout.guideline

class NoteDialogUi(context: Context) {
    private var mContext: Context = context
    var common_dialog_message_tv:EditText?=null
    var guide_line_lly:LinearLayout?=null
    var voice_img_view:ImageView?=null
    var common_dialog_cancel_tv: TextView? = null
    var common_dialog_confirm_tv: TextView? = null
    var common_dialog_root_view: ConstraintLayout? = null

    init {
        common_dialog_root_view = mContext.constraintLayout {
            lparams(width = matchParent, height = matchParent)
            id = R.id.parent_cs_layout
            backgroundColor = resources.getColor(R.color.colortm)

            guideline {
                id = R.id.guide_line_left
            }.lparams(width = wrapContent, height = matchParent) {
                orientation = ConstraintLayout.LayoutParams.VERTICAL
                guidePercent = 0.1F
            }

            guideline {
                id = R.id.guide_line_right
            }.lparams(width = wrapContent, height = matchParent) {
                orientation = ConstraintLayout.LayoutParams.VERTICAL
                guidePercent = 0.9F
            }

            guideline {
                id = R.id.guide_line_top
            }.lparams(width = matchParent, height = wrapContent) {
                orientation = ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent = 0.15F
            }

            guideline {
                id = R.id.guide_line_h_center
            }.lparams(width = matchParent, height = wrapContent) {
                orientation = ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent = 0.5F
            }

            guide_line_lly=linearLayout {
                id = R.id.guide_line_lly
                background = resources.getDrawable(R.drawable.popup_dialog_bg)
                orientation = VERTICAL

                textView {
                    id = R.id.common_dialog_title_tv
                    gravity = Gravity.CENTER_HORIZONTAL
                    textColor = resources.getColor(R.color.colorsNote)
                    textSize = dip(12).toFloat()
                    text = "备注"
                }.lparams(width = matchParent, height = wrapContent) {
                    topMargin = dip(15)
                    bottomMargin=dip(15)
                }

                view {
                    backgroundColor = resources.getColor(R.color.colorsGrayLittle)
                }.lparams(width = matchParent, height = dip(1))

                common_dialog_message_tv=editText {
                    id = R.id.common_dialog_message_tv
                    gravity = Gravity.CENTER + Gravity.BOTTOM
                    background=null
                    singleLine = true
                    hint = "请输入备注信息"
                    textSize = dip(10).toFloat()
                    textColor = resources.getColor(R.color.colorsNote)
                }.lparams(width = matchParent, height = 0) {
                    weight = 1F
                    leftMargin = dip(10)
                    rightMargin = dip(10)
                }

                view {
                    backgroundColor = resources.getColor(R.color.colorsGrayLittle)
                }.lparams(width = matchParent, height = dip(1))

                linearLayout {
                    id = R.id.common_dialog_bottom_ll
                    orientation = HORIZONTAL

                    common_dialog_cancel_tv=textView{
                        id=R.id.common_dialog_cancel_tv
                        isClickable=true
                        gravity=Gravity.CENTER
                        textSize=dip(12).toFloat()
                        text="取消"
                        textColor=resources.getColor(R.color.colorsText)
                    }.lparams(width=0,height = matchParent){
                        weight=1F
                    }

                    view{
                        id=R.id.common_dialog_vertical_line
                        backgroundColor=resources.getColor(R.color.colorsGrayLittle)
                    }.lparams(width=dip(1),height = matchParent)

                    common_dialog_confirm_tv=textView{
                        isClickable=true
                        gravity=Gravity.CENTER
                        textColor=resources.getColor(R.color.colorsText)
                        id=R.id.common_dialog_confirm_tv
                        textSize=dip(12).toFloat()
                        text="确定"
                    }.lparams(width=0,height = matchParent){
                        weight=1F
                    }
                }.lparams(width = matchParent, height = dip(50))
            }.lparams(0, 0) {
                leftToRight = R.id.guide_line_left
                rightToLeft = R.id.guide_line_right
                topToBottom = R.id.guide_line_top
                bottomToTop = R.id.guide_line_h_center
            }

            voice_img_view=imageView {
                image = resources.getDrawable(R.mipmap.ease_record_animate_01)
                id = R.id.voice_img_view
                visibility = View.GONE
            }.lparams(dip(50), dip(60)) {
                leftToRight = R.id.guide_line_left
                rightToLeft = R.id.guide_line_right
                topToBottom = R.id.guide_line_h_center
                bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
            }
        }
    }
}